<?php

namespace app\admin\model\sum\user;

use app\admin\model\sum\Common;

class WalletLog extends Common
{
    protected $name = 'sum_user_wallet_log';

    protected $updateTime = false;

    protected $type = [
        'ext' => 'json'
    ];
    // 追加属性
    protected $append = [
        'event_text'
    ];

    const TYPE_MAP = [
        'money' => '余额',
        'score' => '金币',
        'commission' => '业绩'
    ];

    protected $eventMap = [
        'score' => [
            'card_pay' => '抽卡支付',
            'video_pay' => '短剧支付',
            'gift_pay' => '礼物支付',
            'login' => '登录赠送',
            'signin' => '签到赠送',
            'admin_recharge' => '后台充值',
            'order_recharge' => '线上充值',
            //任务相关
            'task_video_watch'       => '观看视频',
            'task_video_share'       => '分享视频',
            'task_video_comment'     => '评论视频',
            'task_video_like'        => '点赞视频',
            'task_performer_gift'    => '赠送礼物',
            'task_login'    => '登录赠送',
//            'task_performer_rank'    => '进榜单前十',
//            'task_signin_total'      => '累计签到365天',
        ],
        'money' => [
            'order_pay' => '商城订单-余额支付',
            'order_recharge' => '线上充值',
            'admin_recharge' => '后台-余额充值',
            'recharge_gift' => '线上充值-赠送余额',
            'activity_gift' => '活动-赠送余额',
            'order_refund' => '订单退款-退还余额',
            'transfer_by_commission' => '佣金-转入到余额'
        ],
        'commission' => [
            'withdraw' => '提现',
            'withdraw_error' => '提现失败-返还业绩',
            'reward_income' => '业绩-收益',
            'reward_back' => '业绩-退还',
//            'transfer_to_money' => '佣金-转出到余额'
        ]
    ];

    public function getEventMap() {
        return $this->eventMap;
    }

    public function scopeMoney($query)
    {
        return $query->where('type', 'money');
    }

    public function scopeCommission($query)
    {
        return $query->where('type', 'commission');
    }

    public function scopeScore($query)
    {
        return $query->where('type', 'score');
    }

    public function getEventTextAttr($value, $data)
    {
        return $this->eventMap[$data['type']][$data['event']] ?? '';
    }
}
